package com.zy.algorithm.v3.array

import android.os.Bundle
import com.zy.view.DIYSortView
import com.zy.utils.data.Point

//https://leetcode.cn/problems/remove-duplicates-from-sorted-array/description/?envType=study-plan-v2&envId=top-interview-150
// 26. 删除有序数组中的重复项
open class D4LeetCode0080 : BaseV3ArrayFragment() {

    private var array1 = intArrayOf(0, 0, 1, 1, 1, 1, 2, 3, 4, 4)

    override fun getInitD(): Int {
        return 150
    }

    private var baseX = 3
    var baseY = 2


    //33
    private var indexIDes: Point =
        builder.setOriginX(baseX - 1).setOriginY(baseY + 1).setV("i=").setIndex(1000)
            .setVTextSize(48)
            .build(Point.Type.DEFAULT)

    private var indexI: Point =
        builder.setOriginX(baseX).setOriginY(baseY + 1).setV("^").setIndex(10001)
            .build(Point.Type.SUB_SCRIPT)

    //34
    private var indexJDes: Point =
        builder.setOriginX(baseX - 1).setOriginY(baseY + 2).setV("j=").setIndex(1000)
            .setVTextSize(48)
            .build(Point.Type.DEFAULT)
    private var indexJ: Point =
        builder.setOriginX(baseX).setOriginY(baseY + 2).setV("^").setIndex(10002)
            .build(Point.Type.SUB_SCRIPT)

    //35
    private var curNodeDes: Point =
        builder.setOriginX(baseX - 1).setOriginY(baseY + 3).setV("curV").setIndex(1000)
            .setVTextSize(48)
            .build(Point.Type.DEFAULT)

    private var curNode: Point =
        builder.setOriginX(baseX).setOriginY(baseY + 3).setV("0").setIndex(10003)
            .build(Point.Type.DEFAULT)

    //36
    private var lastNodeDes: Point =
        builder.setOriginX(baseX - 1).setOriginY(baseY + 4).setV("lastV").setIndex(1000)
            .setVTextSize(48)
            .build(Point.Type.DEFAULT)

    private var lastNode: Point =
        builder.setOriginX(baseX).setOriginY(baseY + 4).setV("").setIndex(10004)
            .build(Point.Type.DEFAULT)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    }

    override fun setData(diyV4: DIYSortView) {
        title.text = "80. 删除有序数组中的重复项 II"
        diyV4.create(3, 2, array1, Point.Type.DEFAULT)
        diyV4.changeType = DIYSortView.TYPE_COVER

        addAss()
    }

    private fun addAss() {
        diyV4.addPoint(indexIDes)
        diyV4.addPoint(indexI)
        diyV4.addPoint(indexJDes)
        diyV4.addPoint(indexJ)
//        diyV4.addAss(curNodeDes)
//        diyV4.addAss(curNode)
        diyV4.addPoint(lastNodeDes)
        diyV4.addPoint(lastNode)
        diyV4.postInvalidate()
    }
}